package com.ficus.road.maintain.service.smartnew;

import com.ficus.road.maintain.core.model.smartnew.SmartRoadSection;
import com.ficus.road.maintain.dao.smartnew.SmartProjectDao;
import com.ficus.road.maintain.util.MyDateUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author xiawen yang
 * @date 2022/3/3 下午3:45
 */
@Service
@RequiredArgsConstructor
public class SmartProjectService {
    private final SmartProjectDao smartProjectDao;

    public SmartRoadSection saveOrUpdate(SmartRoadSection smartRoadSection) {
        return smartProjectDao.saveOrUpdate(smartRoadSection);
    }

    public List<SmartRoadSection> findByRoadType(Query query) {
        // todo: 获取工程项目数据, 暂时获取今年的
        query.addCriteria(Criteria.where("timestamp").gte(MyDateUtil.strParseDate(MyDateUtil.getYear(new Date()) + "-01-01", "yyyy-MM-dd").getTime() / 1000));
        return smartProjectDao.findByQuery(query);
    }

    public void deleteAll() {
        smartProjectDao.deleteAll();
    }
}
